<template>
     <rx-layout>
            <template v-slot:header>
                <rx-filters :isBpmClient="false"
                            :isMyBpm="isMyBpmClient"
                            :readType="readType"
                            :readKey="readKey"
                            :screenName="screenName"
                            :keyname="getTreeCatByList.key" :namelit="getTreeCatByList.name"
                            @loadListByParams="loadListByParams"
                            :placeholder="i18n('enterName','请输入标题名称')"></rx-filters>
            </template>
            <template v-slot:center>
                <rx-grid ref="rxGrid" :queryParam="queryParam" :url="'/api-bpm/bpm/core/bpmInstTracked/getMyTracked'">
                    <template v-slot:center="{record}">
                        <view class="rx-center" @click="bpmDetails(record)">
                            <view class="rx-createTime">
                                <my-icon style="color: rgba(66, 133, 244, 1);font-size: 1.2rem"
                                         type="icon-linetime"></my-icon>
                                <view class="rx-createTime-name">{{ record.createTime }}</view>
                            </view>
                            <view class="rx-top">
                                <view class="rx-icon-le"><view class="rx-icon_liucheng"><my-icon type="icon-Vue3jpaas-icon_liucheng"></my-icon></view></view>
                                <view class="rx-subject">{{record.bpmInst.subject }}</view>
                            </view>
                            <view class="rx-bottom">
                                <view>
                                    <span class="rx-bottom-span">{{ i18n('processStep', '处理步骤') }}</span>
                                    <span>{{ $i18(record.curNode) }}</span>
                                </view>
                            </view>
                            <view class="rx-operate" >
                                <view class="rx-operate-button" @click.stop="removeTracked(record)">
                                    <my-icon type="icon-Vue3jpaas-icon_huifu"></my-icon>
                                    {{ i18n('cancelTrack', '取消跟踪') }}
                                </view>
                            </view>
                        </view>
                    </template>
                </rx-grid>
            </template>
        </rx-layout>
</template>

<script>
import RxGrid from '@/components/RxGrid'
import RxLayout from '@/components/RxLayout'
import RxFilters from '@/components/RxFilters'
import instAndTaskShareApi from "@/api/instAndTaskShareApi";
import getStatusHtml from '@/common/getStatusHtml.js'
import GatewayApi from "@/api/Gateway/GatewayApi";

export default {
    name: "RxMyTracked",
    components: {RxGrid, RxLayout, RxFilters},
    mixins: [getStatusHtml],
    data() {
        return {
            isMyBpmClient: true,
            readKey: "task.read",
            readType: "instTracked",
            isInit: true,
            getTreeCatByList: '',
            queryParam: {},//筛选参数
            screenName: 'SUBJECT'
        }
    },
    created() {
        this.getTreeCatByKey()
    },
    onShow(){
        if(this.$refs.rxGrid){
            this.$refs.rxGrid.getInit(true, true);
        }
    },
    methods: {
        i18n(name, text, key) {
            return this.$ti18(name, text, "bpmLang", key);
        },
        getTreeCatByKey() {
            instAndTaskShareApi.getTreeCatByKey().then(ret => {
                this.getTreeCatByList = ret;
            })
        },
        //筛选
        loadListByParams(params) {
            this.queryParam = params
        },
        bpmDetails(record) {
            let params = {
                instId: record.instId,
                routerName: 'openDoc',
                action: 'detail'
            }
            let mobileAppId = uni.getStorageSync("mobileAppId");
            if (mobileAppId) {
                params['appId'] = mobileAppId
            }
            uni.navigateTo({
                url: '/views/modules/bpm/OpenDoc?params=' + JSON.stringify(params)
            })
        },
        removeTracked(record) {
            let self = this;
            uni.showModal({
                title:this.$ti18('rxMsa.tipsInfo','提示信息'),
                content: this.i18n('sureCancel', '你确定要取消跟踪吗?'),
                confirmText: self.$ti18('rxForm.okBtn', '确定'),
                cancelText: self.$ti18('rxForm.cancelBtn', '取消'),
                success: function (res) {
                    if (res.confirm) {
                        GatewayApi.removeTracked(record.instId).then(res => {
                            if (res.success) {
                                uni.showToast({
                                    title: res.message, // 消息内容
                                    duration: 2000, // 持续时间（单位：毫秒）
                                    icon: 'none' // 图标类型（可选值：success/loading/none）
                                });
                                self.$refs.rxGrid.getInit(true,true)
                            }else {
                                uni.showToast({
                                    title: res.message, // 消息内容
                                    duration: 2000, // 持续时间（单位：毫秒）
                                    icon: 'none' // 图标类型（可选值：success/loading/none）
                                });
                            }
                        })
                    } else if (res.cancel) {
                        console.log('用户点击取消');
                    }
                }
            });
        }
    }
}
</script>

<style scoped>
@import "../RxProcessManagement.css";
</style>
